<?php
/**
 * UserEdit.php
 *
 * This page is for users to edit their account information such as their password, 
 * email address, etc. Their usernames can not be edited. When changing their
 * password, they must first confirm their current password.
 *
 * Updated by: The Angry Frog
 * Last Updated: August 26, 2004
 */

include("header.php");

/**
 * User has submitted form without errors and user's
 * account has been edited successfully.
 */
if(isset($_SESSION['useredit']))
{
	unset($_SESSION['useredit']);
	header('refresh: 5; url=index.php');?>
    <div id="form_container">
        <div id="title_container">
            <div id="title">
                <p>User Account</p>
            </div>
            <div id="title_link">
            </div>
        </div>
        <div id="form_content">
            <div id="form_text" style="width:668px; border:1px solid green; color:green;">User Account Edit Success!</div>
            <div id="form_text"><b><?php echo $session->username; ?></b>, your account has been successfully updated.</div>
            <div id="form_text"></div>
            <div id="form_text">You will be redirected to the Home page in 5 seconds, if not <a href="index.php">click here</a>...</div>
        </div>
    </div>
<?php }
else
{
	/**
	 * If user is not logged in, then do not display anything.
	 * If user is logged in, then display the form to edit
	 * account information, with the current email address
	 * already in the field.
	 */ 
	if(!$session->logged_in)
	{
    	header('refresh: 5; url=index.php');?>
		<div id="form_container">
            <div id="title_container">
                <div id="title">
                    <p>User Account</p>
                </div>
                <div id="title_link">
                </div>
            </div>
            <div id="form_content">
                <div id="form_text" style="padding:4px; border:1px solid ref; color:red;">Access Denied!</div>
                <div id="form_text"><b><?php echo $session->username; ?></b>, you don't have the right to access this page.</div>
                <div id="form_text"></div>
                <div id="form_text">You will be redirected to the Home page in 5 seconds, if not <a href="index.php">click here</a>...</div>
            </div>
        </div>
	<?php }
    else
	{?>	
<div id="form_container">
    <div id="title_container">
        <div id="title">
            <p>User Account Edit : <?php echo $session->username; ?></p>
        </div>
    </div>
    <div id="form_content">
    	<?php if($form->num_errors > 0)
            { ?>
            <div id="form_error">
            	<?php echo $form->num_errors; ?> error(s) found
            </div>
        <?php } ?>
        <form action="process.php" method="post">
        <input type="hidden" name="subedit" value="1">	
            <ul>
            <fieldset><legend>Login Information</legend>
            	<li id="li_curpass">
                    <label id="label_curpass" for="curpass">Current Password <?php echo $form->error("curpass"); ?></label>
                    <input id="curpass" name="curpass" type="password" size="30" maxlength="30" value="<?php echo $form->value("curpass"); ?>" />
                </li>
            	<li id="li_newpass">
                    <label id="label_newpass" for="newpass">New Password <?php echo $form->error("newpass"); ?></label>
                    <input id="newpass" name="newpass" type="password" size="30" maxlength="30" value="<?php echo $form->value("newpass"); ?>" />
                </li>
                <li id="li_conf_newpass">
                    <label id="label_conf_newpass" for="conf_newpass">Confirm New Password <?php echo $form->error("newpass"); ?></label>
                    <input id="conf_newpass" name="conf_newpass" type="password" size="30" maxlength="30" value="<?php echo $form->value("newpass"); ?>" />
                </li>
            </fieldset>
            <fieldset><legend>Personal Information</legend>
            	<li id="li_firstName">
                    <label id="label_firstName" for="firstName">First Name <?php echo $form->error("firstName"); ?></label>
                    <input id="firstName" name="firstName" type="text" size="30" maxlength="30" 
                    value="<?php if($form->value('firstName') == ""){echo $session->userinfo['firstName'];}else{echo $form->value("firstName");}?>" />
                </li>
            	<li id="li_newpass">
                    <label id="label_lastName" for="lastName">Last Name <?php echo $form->error("lastName"); ?></label>
                    <input id="lastName" name="lastName" type="text"  size="30" maxlength="30" 
                    value="<?php if($form->value('lastName') == ""){echo $session->userinfo['lastName'];}else{echo $form->value("lastName");}?>"/>
                </li>
            </fieldset>
            <fieldset><legend>Contact Information</legend>
            	<li id="li_phoneNumber">
                    <label id="label_phoneNumber" for="phoneNumber">Phone Number <?php echo $form->error("phoneNumber"); ?></label>
                    <input id="phoneNumber" type="text" name="phoneNumber" size="30" placeholder="(___) ___-____ x._____"
                    value="(<?php echo $session->userinfo['areaCode']; ?>) <?php echo $session->userinfo['prefix']; ?>-<?php echo $session->userinfo['lineNumber']; ?> x.<?php echo $session->userinfo['lineExt']; ?>"/>
                </li>
                <li id="li_email">
                    <label id="label_email" for="email">Last Name <?php echo $form->error("email"); ?></label>
                    <input id="email" name="email" type="text" 
                    value="<?php if($form->value("email") == ""){echo $session->userinfo['email'];}else{echo $form->value("email");}?>" size="30" maxlength="30" />
                </li>
            </fieldset>
            <fieldset><legend>About User</legend>
                <li id="li_about">
                	<textarea id="about" class="large" name="about"><?php if($form->value("about") == ""){echo $session->userinfo['about'];}else{echo $form->value("about");}?></textarea>
                </li>
            </fieldset>
                <li class="button">
                    <input class="submit" type="submit" value="Edit Account">
                    <input class="submit" type="button" name="cancel" value="Cancel" onclick="location.href = 'userinfo.php?user=<?php echo $session->username;?>'"/>
                </li>
            </ul>
        </form>
	</div>
</div>
<!-- live typecasting -->
<script type="text/javascript" src="jscripts/jquery.maskedinput-1.3.js" ></script>
<script>
jQuery(function($){
   $("#phoneNumber").mask("(###) ###-####? x.#####");
});
</script>
	<?php }
}
include('footer.php');
?>